package com.piece.module.generator.model;

import com.piece.core.framework.util.string.StringUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.io.Serializable;
import java.util.List;

@Data
@Entity
@NoArgsConstructor
@Table(name = "gen_table_column")
@ApiModel(value = "业务字段表:gen_table_column")
public class GenTableColumn implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "column_id", length = 11)
    @ApiModelProperty(value = "主键")
    private Long columnId;

    @Column(name = "table_id", length = 11)
    @ApiModelProperty(value = "归属表编号")
    private Long tableId;

    @Column(name = "table_name", length = 32)
    @ApiModelProperty(value = "归属表名称")
    private String tableName;

    @Column(name = "column_name", length = 32)
    @ApiModelProperty(value = "列名称")
    private String columnName;

    @Column(name = "column_comment", length = 512)
    @ApiModelProperty(value = "列描述")
    private String columnComment;

    @Column(name = "column_type", length = 128)
    @ApiModelProperty(value = "列类型")
    private String columnType;

    @Column(name = "java_type", length = 128)
    @ApiModelProperty(value = "JAVA类型")
    private String javaType;

    @Column(name = "java_field", length = 128)
    @ApiModelProperty(value = "JAVA字段名")
    private String javaField;

    @Column(name = "is_pk", length = 1)
    @ApiModelProperty(value = "是否主键", notes = "0=是, 1=否")
    private String isPk;

    public boolean isPk() {
        return isPk != null && StringUtil.equals("0", isPk);
    }

    @Column(name = "is_increment", length = 1)
    @ApiModelProperty(value = "是否自增", notes = "0=是, 1=否")
    private String isIncrement;

    @Column(name = "is_required", length = 1)
    @ApiModelProperty(value = "是否必填", notes = "0=是, 1=否")
    private String isRequired;

    @Column(name = "is_insert", length = 1)
    @ApiModelProperty(value = "是否为插入字段", notes = "0=是, 1=否")
    private String isInsert;

    @Column(name = "is_edit", length = 1)
    @ApiModelProperty(value = "是否编辑字段", notes = "0=是, 1=否")
    private String isEdit;

    @Column(name = "is_list", length = 1)
    @ApiModelProperty(value = "是否列表字段", notes = "0=是, 1=否")
    private String isList;

    @Column(name = "is_query", length = 1)
    @ApiModelProperty(value = "是否查询字段", notes = "0=是, 1=否")
    private String isQuery;

    @Column(name = "query_type", length = 10)
    @ApiModelProperty(value = "查询方式", notes = "EQ等于、NEQ不等于、GT大于、LT小于、GE大于等于、LE小于等于、LK模糊、IN包含、NIN不包含、EMP空、NEMP不为空、NULL、NNULL、BETWEEN范围")
    private String queryType;

    @Column(name = "html_type", length = 30)
    @ApiModelProperty(value = "显示类型", notes = "input文本框、textarea文本域、select下拉框、checkbox复选框、radio单选框、datetime日期控件")
    private String htmlType;

    @Column(name = "dict_type", length = 128)
    @ApiModelProperty(value = "字典类型")
    private String dictType;

    @Column(name = "sort", length = 3)
    @ApiModelProperty(value = "排序")
    private Integer sort;

    @Transient
    @ApiModelProperty(value = "验证规则")
    private List<TbSysValidate> validates;
}
